package com.peaksport.framework.metadata.venum;

import com.peaksport.framework.exception.PKDevException;

/**
 * 比较类型
 * @author jinbin_guo  2019年4月15日 下午4:41:59
 *
 */
public enum CompareTypeEnum  {
	
    EQUALS("="),GREATER(">"),LESS("<"),
    GREATER_EQUALS(">="),LESS_EQUALS("<="),NOTEQUALS("<>"),
    LIKE("like"),NOTLIKE("not like"),
    INCLUDE("in"),NOTINCLUDE("not in"),
    IS("is"),ISNOT("is not"),
    EXISTS("exists"),NOTEXISTS("not exists");

    private String value;

    private CompareTypeEnum(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public static CompareTypeEnum get(String compareTypeValue) {
        if (compareTypeValue ==  null) throw PKDevException.throwException("比较枚举值不能为空.");
        compareTypeValue = compareTypeValue.trim();
        if ("=".equals(compareTypeValue))  return EQUALS;
        else if (">".equals(compareTypeValue))  return GREATER;
        else if ("<".equals(compareTypeValue))  return LESS;
        else if (">=".equals(compareTypeValue))  return GREATER_EQUALS;
        else if ("<=".equals(compareTypeValue))  return NOTEQUALS;
        else if ("like".equals(compareTypeValue))  return LIKE;
        else if ("not like".equals(compareTypeValue))  return NOTLIKE;
        else if ("in".equals(compareTypeValue))  return INCLUDE;
        else if ("not in".equals(compareTypeValue))  return NOTINCLUDE;
        else if ("is".equals(compareTypeValue))  return IS;
        else if ("is not".equals(compareTypeValue))  return ISNOT;
        else if ("exists".equals(compareTypeValue))  return EXISTS;
        else if ("not exists".equals(compareTypeValue))  return NOTEXISTS;
        else throw PKDevException.throwException("暂未支持的比较枚举值[%s],请联系统管理人员.", compareTypeValue);
    }

    @Override
    public String toString() {
        return value;
    }
}
